package com.link.base.base.message.push.service;

import com.link.base.base.message.push.dao.mybatis.mapper.PushMapper;
import com.link.base.base.message.push.model.PushInfo;
import javax.annotation.Resource;

import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * 消息管理 - 消息定时推送工作流
 * 
 * @author ouyangzhenqiang
 * @date 2018/10/26
 */
@Component
public class PushServiceTask {
    @Resource
    private PushMapper pushMapper;
    @Resource
    private JpushServiceImpl jpushServiceImpl;
    @Resource
    private WebPushServiceImpl webPushServiceImpl;

    /**
     * 查询需推送的业务数据消息 - app 极光渠道
     * 
     * @author ouyangzhenqiang
     * @date 2018/10/26
     */
    public void pushToNormalApp() {
        try {
            List<PushInfo> pushList = pushMapper.getNormalAppPushList();
            if (pushList.size() > 0) {
                try {
                    jpushServiceImpl.jpushList(pushList);
                } catch (Exception e) {
                    LCLogger.error().withMessageKey("pushToNormalApp")
                        .withMessage("该批次app消息推送失败->" + e.getMessage()).flush();
                }
            }
        } catch (Exception e) {
            LCLogger.error().withMessageKey("pushToNormalApp")
                .withMessage("该批次app消息推送失败->" + e.getMessage()).flush();
        }
    }

    /**
     * 查询需推送的业务数据消息 - web
     *
     * @author ouyangzhenqiang
     * @date 2019/07/25 17:21
     */
    public void pushToWeb() {
        try {
            List<PushInfo> pushList = pushMapper.getWebPushList();
            if (pushList.size() > 0) {
                try {
                    webPushServiceImpl.webPushList(pushList);
                } catch (Exception e) {
                    LCLogger.error().withMessageKey("pushToWeb")
                        .withMessage("该批次web消息推送失败->" + e.getMessage()).flush();
                }
            }
        } catch (Exception e) {
            LCLogger.error().withMessageKey("pushToWeb")
                .withMessage("该批次web消息推送失败->" + e.getMessage()).flush();
        }
    }
}